#!/usr/bin/perl
my $ans = 0;
my $dept = 0;
my $newLine;
my $isNext = 0;
my $hasStarted = 0;
open (FILE, '>courses.txt');
while(<>){
	chomp;
	if($_ =~ m/([\w\s'&,:\+\/-]+)fee/){
                print FILE "        $1\n";
        }

	elsif($_ =~ m/(^[A-Z]\s?[A-Z]?[A-Z]? \d\d\d[A-Z]?)([\d,]? -)*/){
		#if($_ =~ m/([\w\s'&]+)fee/){
        	#       print FILE "        $1\n";
	        #}

		if($isNext == 1 && $2){
			$newStr = substr($_, 0, length($_)-2);
			print FILE "			$newStr\n";
		}	
		else{
			if($hasStarted){
				print FILE "	$1\n" unless ($2);
				$isNext = 0;
			}
		}
	}
	elsif($_ =~ m/^[A-Z\-]+, [A-Z]/){
		$newStr2 = substr($_, 0, length($_)-2);
		print FILE "			$newStr2\n";
	}
	elsif($_ =~ m/^([\w\s\-]+ - [A-Z\s]+) \D/){
		$hasStarted = 1;
		print FILE "$1\n";
	}
#	elsif($_ =~ m/([\w\s'&]+)fee/){
#                print FILE "	    $1\n";
#        }

	elsif(ord(substr($_, 0, 1)) == 149){
		$newLine = substr($_, 1, length($_)-2);
		$newLine =~ /([\d]{5})([\S\s]*)/;
		print FILE "		$1\n";
		print FILE "			$2\n" unless length($2)<2;		
		$isNext = 1;
	}
	
}
